using System;
using System.Collections;
using System.Globalization;
using Sedna.Core.Controller;
using Sedna.Core.Controller.Configurations;
using Sedna.Core.Controls.Support;


namespace Sedna.Core.pages.Controls.DatePicker
{
    /// <summary>
    /// Localisation file for JavaScritp Calendar used in ImsDatePicker.
    /// </summary>
	
	
    public class normal : BasePage, IConfigurationAware
    {
        protected DateTimeFormatInfo dateFormat;
        protected DateTime dateFrom;
        protected DateTime dateTo;
        //protected IBusinessCalendarService businessCallendarService;
        protected string calendarConfigurationId;
        protected IConfiguration calendarConfiguration;
		
        public normal()
        {
            calendarConfigurationId = "configuration.default.Calendar";
        }

        public string DateSeparator
        {
            get { return JavascriptUtil.EncloseWithQuotes(dateFormat.DateSeparator);}
        }

        public string AbbreviatedDayNames
        {
            get {return JavascriptUtil.ToScriptObject(dateFormat.AbbreviatedDayNames);}
        }

        public string DayNames
        {
            get {return JavascriptUtil.ToScriptObject(dateFormat.DayNames);}
        }

        public string MonthNames
        {
            get {return JavascriptUtil.ToScriptObject(dateFormat.MonthNames);}
        }

        public string AbbreviatedMonthNames
        {
            get {return JavascriptUtil.ToScriptObject(dateFormat.AbbreviatedMonthNames);}
        }

        public int FirstDayOfWeek
        {
            get {return (int)dateFormat.FirstDayOfWeek;}
        }

        public string DatePattern
        {
            get {return JavascriptUtil.EncloseWithQuotes(dateFormat.ShortDatePattern);}	
        }
		
        /*public string Holidays
        {
            get
            {
                BusinessDateRange businessDateRange = businessCallendarService.SubRange(dateFrom, dateTo);
                ArrayList holidays = new ArrayList();
                for(DateTime date = dateFrom; date < dateTo; date = date.AddDays(1))
                {
                    if (businessDateRange[date])
                    {
                        continue;
                    }
                    string dateEntry = "{" + String.Format("'y':{0},'m':{1},'d':{2}", date.Year, date.Month, date.Day) + "}";
                    holidays.Add(dateEntry);
                }
                return string.Join(",", (string[]) holidays.ToArray(typeof(string)));
            }
        }*/

        public int DateFormatSequence
        {
            get
            {
                int yearPosition=dateFormat.ShortDatePattern.IndexOf('y');
                int monthPosition=dateFormat.ShortDatePattern.IndexOf('M');
                int dayPosition=dateFormat.ShortDatePattern.IndexOf('d');
                if (yearPosition!=-1&&yearPosition<monthPosition&&yearPosition<dayPosition)
                {
                    return 2;
                }
                if (monthPosition!=-1&&monthPosition<dayPosition&&monthPosition<yearPosition)
                {
                    return 1;
                }
                return 0;
            }
        }

        override protected void OnInit(EventArgs e)
        {
            IDPCalendarConfiguration dpCalConfiguration=(IDPCalendarConfiguration)SpringContextFactory.GetContext().GetObject(calendarConfigurationId);
            dateFormat=dpCalConfiguration.PrincipalWrapper.Culture.DateTimeFormat;
            //businessCallendarService = (IBusinessCalendarService) SpringContextFactory.GetContext().GetObject(dpCalConfiguration.BusinessCalendarServiceCtxId);
            dateFrom = DateTime.Today.AddMonths(-dpCalConfiguration.MonthBeforeDate);
            dateTo = DateTime.Today.AddMonths(dpCalConfiguration.MonthAfterDate);
		
            base.OnInit(e);
        }
		
    }
}

